package com.bwie.parkdemo.mvvm.model.entity;

import com.bwie.lib_core.base.BaseEntity;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * 巡逻分组接口获取返回值
 * {
 "values": "[{\"gId\":47,\"gName\":\"巡逻1\",
 \"isLiable\":1,\"uId\":1}]",
 }
 * */
public class GroupEntity extends BaseEntity {

    private String values;
    private List<Object>datas;

    public void setValues(String values) {
        this.values = values;
    }

    public List<Object> getDatas() {
        datas = new ArrayList<>();
        try {
            JSONArray jay = new JSONArray(values);
            for (int i = 0;i < jay.length();i ++){
                String jsonStr = jay.getJSONObject(i).toString();
                Values entity = new Gson().fromJson(jsonStr,Values.class);
                datas.add(entity);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return datas;
    }

    public static class Values{
        public int gId;
        public String gName;
        public int isLiable;
        public int uId;
    }
}
